import { Popconfirm } from "antd";
import { omit } from "lodash-es";
import BasicButton from "./BasicButton";
import React, { useMemo } from "react";

export default function PopConfirmButton(props: { enable?: true } & ComponentNode) {
	// get inherit binding value
	const getBindValues = useMemo(() => {
		return Object.assign(
			{
				okText: "确定",
				cancelText: "取消"
			},
			{ ...props }
		);
	}, [props]);

	const bindValues = omit(getBindValues, "icon");
	const btnBind = omit(bindValues, "title");
	if (btnBind.disabled) btnBind.color = "";
	const Button = React.createElement(BasicButton, btnBind, props.children);

	// If it is not enabled, it is a normal button
	return !props.enable ? Button : React.createElement(Popconfirm, bindValues, Button);
}
